<template>
    <template v-if="user" >
      <van-card class="card"
                desc="关注: 4  粉丝: 7"
                :title="`${user.userAccount}`"
                :thumb="`${user.avatarUrl}`"
      >
        <template #tags>
          <van-tag plain type="primary" v-for="(tag, index) in JSON.parse(user.tags)" :key="index" style="margin-right: 8px; margin-top: 8px">
            {{tag}}
          </van-tag>
        </template>
      </van-card>
      <van-cell title="编辑个人信息" is-link to="/user/update" >
        <template #icon >
          <svg-icon icon-name="icon-bianji" class="left-icon"></svg-icon>
        </template>
      </van-cell>
      <van-cell title="我创建的队伍" is-link to="/user/team/create" >
        <template #icon >
          <svg-icon icon-name="icon-branches" class="left-icon"></svg-icon>
        </template>
      </van-cell>
      <van-cell title="我加入的队伍" is-link to="/user/team/join" >
        <template #icon >
          <svg-icon icon-name="icon-zudui" class="left-icon"></svg-icon>
        </template>
      </van-cell>
      <van-cell title="设置" is-link to="/setting">
        <template #icon >
          <svg-icon icon-name="icon-shezhi" class="left-icon"></svg-icon>
        </template>
      </van-cell>
    </template>

</template>

<script setup lang="ts">
import {useRoute, useRouter} from "vue-router";
import {onMounted, ref} from "vue";
import myAxios from "../plugins/myAxios";
import {Toast} from "vant";
import {getCurrentUser} from "../services/user";
import SvgIcon from "../components/SvgIcon.vue";



const user = ref();
const router = useRouter();

onMounted(async () => {
  user.value = await getCurrentUser();
})

const toEdit = (editKey: string, editName: string, currentValue: string) => {
  router.push({
    path: '/user/edit',
    query: {
      editKey,
      editName,
      currentValue,
    }
  })
}

/*const onClick = async () => {
  const res = await myAxios.post('/user/logout');
  console.log(res, '用户退出登录');
  if (res.code === 0 && res.data) {
    Toast.success('退出登录成功');
    // 跳转到之前的页面
    /!*const redirectUrl = route.query?.redirect as string ?? '/uer/login';
    window.location.href = redirectUrl;*!/
    await router.push('/user/login');
  } else {
    Toast.fail('退出登录失败');
  }
};*/

</script>

<style scoped>
.left-icon{
  margin-top: 4px;
  margin-right: 4px;
}
/*.logout-cell {
!*  text-align: center;*!
  color: #d86262;
  height: 120px;
  margin-top: 9px;
}
.logout-icon{
  color: #d86262;
  margin-left: 38%;
  margin-right: 5px;
  margin-top: 4px;
}*/
.card{
  margin-left: 5px;
  margin-right: 5px;
  border-radius: 10px !important;
  overflow: hidden;
  background: url("../assets/userBack.webp");
  background-size: cover;
}

.card ::v-deep(.van-card__title) {
  color: black;
  font-family: "MV Boli",cursive;
  font-size: 20px;
}

.card ::v-deep(.van-card__desc) {
  margin-top: 8px;
  color: #ee0a24;
  font-size: 16px;
  font-family: "Arial",serif;
}
</style>
